package com.example.plat.util;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Component
public class ImageHandle {

    @Value("${SavePath.path}")
    String defaultPath;
    //上传图片
    public void upload(MultipartFile fileUpload){
        //获取文件名
        String fileName = fileUpload.getOriginalFilename();

        //没有路径就创建路径
        File tmp = new File(defaultPath);
        if (!tmp.exists()) {
            tmp.mkdirs();
        }
        String resourcesPath = defaultPath + fileName;

        File upFile = new File(resourcesPath);
        try {
            fileUpload.transferTo(upFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

//    - 文件上传：1.表单提交方式必须是post    2.表单enctype属性必须为 multipart/form-data
//    <form th:action="@{/employee/save}" method="post" enctype="multipart/form-data">

}
